export default {
    data() {
        return {
            screenHeight: document.body.clientHeight, // 这里是给到了一个默认值 （这个很重要）
            tableHeight: null, // 表格高度
            bottomOffset: 50, //分页高度
        };
    },

    watch: {
        // 监听屏幕高度改变表格高度
        screenHeight(val) {
            // 初始化表格高度
            const { offsetTop, offsetHeight } = this.$refs.header.$el;
            let pageNode = document.querySelector(".el-pagination");
            let pageH = pageNode ? pageNode.offsetHeight : 0;
            let extraH = this.extraHeigh != undefined ? this.extraHeigh : 0;
            this.tableHeight =
                val - (offsetTop + offsetHeight + this.bottomOffset + pageH + extraH);
        },
    },
    beforeDestroy() {
        window.removeEventListener("resize", this.resizeHandler);
    },
    deactivated() {
        window.removeEventListener("resize", this.resizeHandler);
    },
    mounted() {
        // 监听屏幕高度

        let pageNode = document.querySelector(".el-pagination");
        let pageH = pageNode ? pageNode.offsetHeight : 0;
        const { offsetTop, offsetHeight } = this.$refs.header.$el;
        let extraH = this.extraHeigh != undefined ? this.extraHeigh : 0;
        this.tableHeight =
            this.screenHeight -
            (offsetTop + offsetHeight + this.bottomOffset + pageH + extraH);

        window.addEventListener("resize", this.resizeHandler);
    },
    methods: {
        resizeHandler() {
            window.screenHeight = document.body.clientHeight;
            this.screenHeight = window.screenHeight;
        },
    },
};